﻿// Type: System.Windows.Forms.FileDialogNative
// Assembly: System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System.Windows.Forms
{
    static class FileDialogNative
    {
        #region Nested type: CLSIDGuid

        internal class CLSIDGuid
        {
            internal const string FileOpenDialog = "DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7";
            internal const string FileSaveDialog = "C0B4E2F3-BA21-4773-8DBA-335EC946EB8B";

            private CLSIDGuid() { }
        }

        #endregion

        #region Nested type: COMDLG_FILTERSPEC

        [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)]
        internal struct COMDLG_FILTERSPEC
        {
            [MarshalAs(UnmanagedType.LPWStr)]
            internal string pszName;

            [MarshalAs(UnmanagedType.LPWStr)]
            internal string pszSpec;
        }

        #endregion

        #region Nested type: FDE_OVERWRITE_RESPONSE

        internal enum FDE_OVERWRITE_RESPONSE
        {
            FDEOR_DEFAULT,
            FDEOR_ACCEPT,
            FDEOR_REFUSE,
        }

        #endregion

        #region Nested type: FDE_SHAREVIOLATION_RESPONSE

        internal enum FDE_SHAREVIOLATION_RESPONSE
        {
            FDESVR_DEFAULT,
            FDESVR_ACCEPT,
            FDESVR_REFUSE,
        }

        #endregion

        #region Nested type: FOS

        [Flags]
        internal enum FOS : uint
        {
            FOS_OVERWRITEPROMPT = 2U,
            FOS_STRICTFILETYPES = 4U,
            FOS_NOCHANGEDIR = 8U,
            FOS_PICKFOLDERS = 32U,
            FOS_FORCEFILESYSTEM = 64U,
            FOS_ALLNONSTORAGEITEMS = 128U,
            FOS_NOVALIDATE = 256U,
            FOS_ALLOWMULTISELECT = 512U,
            FOS_PATHMUSTEXIST = 2048U,
            FOS_FILEMUSTEXIST = 4096U,
            FOS_CREATEPROMPT = 8192U,
            FOS_SHAREAWARE = 16384U,
            FOS_NOREADONLYRETURN = 32768U,
            FOS_NOTESTFILECREATE = 65536U,
            FOS_HIDEMRUPLACES = 131072U,
            FOS_HIDEPINNEDPLACES = 262144U,
            FOS_NODEREFERENCELINKS = 1048576U,
            FOS_DONTADDTORECENT = 33554432U,
            FOS_FORCESHOWHIDDEN = 268435456U,
            FOS_DEFAULTNOMINIMODE = 536870912U,
        }

        #endregion

        #region Nested type: IFileDialog

        [Guid("42f85136-db7e-439c-85f1-e4075d135fc8")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [ComImport]
        internal interface IFileDialog
        {
            [MethodImpl(MethodImplOptions.PreserveSig)]
            int Show([In] IntPtr parent);

            void SetFileTypes([In] uint cFileTypes,
                              [MarshalAs(UnmanagedType.LPArray), In] COMDLG_FILTERSPEC[] rgFilterSpec);

            void SetFileTypeIndex([In] uint iFileType);

            void GetFileTypeIndex(out uint piFileType);

            void Advise([MarshalAs(UnmanagedType.Interface), In] IFileDialogEvents pfde, out uint pdwCookie);

            void Unadvise([In] uint dwCookie);

            void SetOptions([In] FOS fos);

            void GetOptions(out FOS pfos);

            void SetDefaultFolder([MarshalAs(UnmanagedType.Interface), In] IShellItem psi);

            void SetFolder([MarshalAs(UnmanagedType.Interface), In] IShellItem psi);

            void GetFolder([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void GetCurrentSelection([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void SetFileName([MarshalAs(UnmanagedType.LPWStr), In] string pszName);

            void GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);

            void SetTitle([MarshalAs(UnmanagedType.LPWStr), In] string pszTitle);

            void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr), In] string pszText);

            void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr), In] string pszLabel);

            void GetResult([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void AddPlace([MarshalAs(UnmanagedType.Interface), In] IShellItem psi, int alignment);

            void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr), In] string pszDefaultExtension);

            void Close([MarshalAs(UnmanagedType.Error)] int hr);

            void SetClientGuid([In] ref Guid guid);

            void ClearClientData();

            void SetFilter([MarshalAs(UnmanagedType.Interface)] IntPtr pFilter);
        }

        #endregion

        #region Nested type: IFileDialogEvents

        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [Guid("973510DB-7D7F-452B-8975-74A85828D354")]
        [ComImport]
        internal interface IFileDialogEvents
        {
            [MethodImpl(MethodImplOptions.PreserveSig)]
            int OnFileOk([MarshalAs(UnmanagedType.Interface), In] IFileDialog pfd);

            [MethodImpl(MethodImplOptions.PreserveSig)]
            int OnFolderChanging([MarshalAs(UnmanagedType.Interface), In] IFileDialog pfd,
                                 [MarshalAs(UnmanagedType.Interface), In] IShellItem psiFolder);

            void OnFolderChange([MarshalAs(UnmanagedType.Interface), In] IFileDialog pfd);

            void OnSelectionChange([MarshalAs(UnmanagedType.Interface), In] IFileDialog pfd);

            void OnShareViolation([MarshalAs(UnmanagedType.Interface), In] IFileDialog pfd,
                                  [MarshalAs(UnmanagedType.Interface), In] IShellItem psi,
                                  out FDE_SHAREVIOLATION_RESPONSE pResponse);

            void OnTypeChange([MarshalAs(UnmanagedType.Interface), In] IFileDialog pfd);

            void OnOverwrite([MarshalAs(UnmanagedType.Interface), In] IFileDialog pfd,
                             [MarshalAs(UnmanagedType.Interface), In] IShellItem psi,
                             out FDE_OVERWRITE_RESPONSE pResponse);
        }

        #endregion

        #region Nested type: IFileOpenDialog

        [Guid("d57c7288-d4ad-4768-be02-9d969532d960")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [ComImport]
        internal interface IFileOpenDialog : IFileDialog
        {
            [MethodImpl(MethodImplOptions.PreserveSig)]
            int Show([In] IntPtr parent);

            void SetFileTypes([In] uint cFileTypes, [In] ref COMDLG_FILTERSPEC rgFilterSpec);

            void SetFileTypeIndex([In] uint iFileType);

            void GetFileTypeIndex(out uint piFileType);

            void Advise([MarshalAs(UnmanagedType.Interface), In] IFileDialogEvents pfde, out uint pdwCookie);

            void Unadvise([In] uint dwCookie);

            void SetOptions([In] FOS fos);

            void GetOptions(out FOS pfos);

            void SetDefaultFolder([MarshalAs(UnmanagedType.Interface), In] IShellItem psi);

            void SetFolder([MarshalAs(UnmanagedType.Interface), In] IShellItem psi);

            void GetFolder([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void GetCurrentSelection([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void SetFileName([MarshalAs(UnmanagedType.LPWStr), In] string pszName);

            void GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);

            void SetTitle([MarshalAs(UnmanagedType.LPWStr), In] string pszTitle);

            void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr), In] string pszText);

            void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr), In] string pszLabel);

            void GetResult([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void AddPlace([MarshalAs(UnmanagedType.Interface), In] IShellItem psi, FileDialogCustomPlace fdcp);

            void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr), In] string pszDefaultExtension);

            void Close([MarshalAs(UnmanagedType.Error)] int hr);

            void SetClientGuid([In] ref Guid guid);

            void ClearClientData();

            void SetFilter([MarshalAs(UnmanagedType.Interface)] IntPtr pFilter);

            void GetResults([MarshalAs(UnmanagedType.Interface)] out IShellItemArray ppenum);

            void GetSelectedItems([MarshalAs(UnmanagedType.Interface)] out IShellItemArray ppsai);
        }

        #endregion

        //[Guid("d57c7288-d4ad-4768-be02-9d969532d960")]
        //[CoClass(typeof (FileDialogNative.FileOpenDialogRCW))]
        //[ComImport]
        //internal interface NativeFileOpenDialog : FileDialogNative.IFileOpenDialog, FileDialogNative.IFileDialog
        //{
        //}

        #region Nested type: IFileSaveDialog

        [Guid("84bccd23-5fde-4cdb-aea4-af64b83d78ab")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [ComImport]
        internal interface IFileSaveDialog : IFileDialog
        {
            [MethodImpl(MethodImplOptions.PreserveSig)]
            int Show([In] IntPtr parent);

            void SetFileTypes([In] uint cFileTypes, [In] ref COMDLG_FILTERSPEC rgFilterSpec);

            void SetFileTypeIndex([In] uint iFileType);

            void GetFileTypeIndex(out uint piFileType);

            void Advise([MarshalAs(UnmanagedType.Interface), In] IFileDialogEvents pfde, out uint pdwCookie);

            void Unadvise([In] uint dwCookie);

            void SetOptions([In] FOS fos);

            void GetOptions(out FOS pfos);

            void SetDefaultFolder([MarshalAs(UnmanagedType.Interface), In] IShellItem psi);

            void SetFolder([MarshalAs(UnmanagedType.Interface), In] IShellItem psi);

            void GetFolder([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void GetCurrentSelection([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void SetFileName([MarshalAs(UnmanagedType.LPWStr), In] string pszName);

            void GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);

            void SetTitle([MarshalAs(UnmanagedType.LPWStr), In] string pszTitle);

            void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr), In] string pszText);

            void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr), In] string pszLabel);

            void GetResult([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void AddPlace([MarshalAs(UnmanagedType.Interface), In] IShellItem psi, FileDialogCustomPlace fdcp);

            void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr), In] string pszDefaultExtension);

            void Close([MarshalAs(UnmanagedType.Error)] int hr);

            void SetClientGuid([In] ref Guid guid);

            void ClearClientData();

            void SetFilter([MarshalAs(UnmanagedType.Interface)] IntPtr pFilter);

            void SetSaveAsItem([MarshalAs(UnmanagedType.Interface), In] IShellItem psi);

            void SetProperties([MarshalAs(UnmanagedType.Interface), In] IntPtr pStore);

            void SetCollectedProperties([MarshalAs(UnmanagedType.Interface), In] IntPtr pList, [In] int fAppendDefault);

            void GetProperties([MarshalAs(UnmanagedType.Interface)] out IntPtr ppStore);

            void ApplyProperties([MarshalAs(UnmanagedType.Interface), In] IShellItem psi,
                                 [MarshalAs(UnmanagedType.Interface), In] IntPtr pStore,
                                 [ComAliasName("ShellObjects.wireHWND"), In] ref IntPtr hwnd,
                                 [MarshalAs(UnmanagedType.Interface), In] IntPtr pSink);
        }

        #endregion

        //[CoClass(typeof (FileDialogNative.FileSaveDialogRCW))]
        //[Guid("84bccd23-5fde-4cdb-aea4-af64b83d78ab")]
        //[ComImport]
        //internal interface NativeFileSaveDialog : FileDialogNative.IFileSaveDialog, FileDialogNative.IFileDialog
        //{
        //}

        //[TypeLibType(TypeLibTypeFlags.FCanCreate)]
        //[ClassInterface(ClassInterfaceType.None)]
        //[Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")]
        //[ComImport]
        //internal class FileOpenDialogRCW
        //{
        //  [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
        //  public FileOpenDialogRCW();
        //}

        //[TypeLibType(TypeLibTypeFlags.FCanCreate)]
        //[ClassInterface(ClassInterfaceType.None)]
        //[Guid("C0B4E2F3-BA21-4773-8DBA-335EC946EB8B")]
        //[ComImport]
        //internal class FileSaveDialogRCW
        //{
        //  [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
        //  public FileSaveDialogRCW();
        //}

        #region Nested type: IIDGuid

        internal class IIDGuid
        {
            internal const string IModalWindow = "b4db1657-70d7-485e-8e3e-6fcb5a5c1802";
            internal const string IFileDialog = "42f85136-db7e-439c-85f1-e4075d135fc8";
            internal const string IFileOpenDialog = "d57c7288-d4ad-4768-be02-9d969532d960";
            internal const string IFileSaveDialog = "84bccd23-5fde-4cdb-aea4-af64b83d78ab";
            internal const string IFileDialogEvents = "973510DB-7D7F-452B-8975-74A85828D354";
            internal const string IShellItem = "43826D1E-E718-42EE-BC55-A1E261C37BFE";
            internal const string IShellItemArray = "B63EA76D-1F85-456F-A19C-48159EFA858B";

            private IIDGuid() { }
        }

        #endregion

        #region Nested type: IModalWindow

        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [Guid("b4db1657-70d7-485e-8e3e-6fcb5a5c1802")]
        [ComImport]
        internal interface IModalWindow
        {
            [MethodImpl(MethodImplOptions.PreserveSig)]
            int Show([In] IntPtr parent);
        }

        #endregion

        #region Nested type: IShellItem

        [Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [ComImport]
        internal interface IShellItem
        {
            void BindToHandler([MarshalAs(UnmanagedType.Interface), In] IntPtr pbc, [In] ref Guid bhid,
                               [In] ref Guid riid, out IntPtr ppv);

            void GetParent([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void GetDisplayName([In] SIGDN sigdnName, [MarshalAs(UnmanagedType.LPWStr)] out string ppszName);

            void GetAttributes([In] uint sfgaoMask, out uint psfgaoAttribs);

            void Compare([MarshalAs(UnmanagedType.Interface), In] IShellItem psi, [In] uint hint, out int piOrder);
        }

        #endregion

        #region Nested type: IShellItemArray

        [Guid("B63EA76D-1F85-456F-A19C-48159EFA858B")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [ComImport]
        internal interface IShellItemArray
        {
            void BindToHandler([MarshalAs(UnmanagedType.Interface), In] IntPtr pbc, [In] ref Guid rbhid,
                               [In] ref Guid riid, out IntPtr ppvOut);

            void GetPropertyStore([In] int Flags, [In] ref Guid riid, out IntPtr ppv);

            void GetPropertyDescriptionList([In] ref PROPERTYKEY keyType, [In] ref Guid riid, out IntPtr ppv);

            void GetAttributes([In] SIATTRIBFLAGS dwAttribFlags, [In] uint sfgaoMask, out uint psfgaoAttribs);

            void GetCount(out uint pdwNumItems);

            void GetItemAt([In] uint dwIndex, [MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);

            void EnumItems([MarshalAs(UnmanagedType.Interface)] out IntPtr ppenumShellItems);
        }

        #endregion

        #region Nested type: PROPERTYKEY

        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        internal struct PROPERTYKEY
        {
            internal Guid fmtid;
            internal uint pid;
        }

        #endregion

        #region Nested type: SIATTRIBFLAGS

        internal enum SIATTRIBFLAGS
        {
            SIATTRIBFLAGS_AND = 1,
            SIATTRIBFLAGS_OR = 2,
            SIATTRIBFLAGS_APPCOMPAT = 3,
        }

        #endregion

        #region Nested type: SIGDN

        internal enum SIGDN : uint
        {
            SIGDN_NORMALDISPLAY = 0U,
            SIGDN_PARENTRELATIVEPARSING = 2147581953U,
            SIGDN_DESKTOPABSOLUTEPARSING = 2147647488U,
            SIGDN_PARENTRELATIVEEDITING = 2147684353U,
            SIGDN_DESKTOPABSOLUTEEDITING = 2147794944U,
            SIGDN_FILESYSPATH = 2147844096U,
            SIGDN_URL = 2147909632U,
            SIGDN_PARENTRELATIVEFORADDRESSBAR = 2147991553U,
            SIGDN_PARENTRELATIVE = 2148007937U,
        }

        #endregion
    }
}
